package com.kangfawei.thread;

/**
 * @author 康发伟
 * yield礼让线程，线程由运行状态直接进入就绪状态
 */
public class YieldDemo implements Runnable {
    @Override
    public void run() {
        for(int i = 0 ; i < 100 ; i++){
            if(i % 10 == 0){
                Thread.yield();
                System.out.println(Thread.currentThread().getName() + "礼让...");
            }
            System.out.println(Thread.currentThread().getName() + "-->" + i);
        }
    }

    public static void main(String[] args){
        YieldDemo demo1 = new YieldDemo();
        YieldDemo demo2 = new YieldDemo();
        new Thread(demo1).start();
        new Thread(demo2).start();
    }
}
